<template>
	<view class="content">
		<view class="content_shang">
			<view class="shang_shang">
				<view class="shang_left">
					货源
				</view>
				<view class="shang_right">
					<image src="../../static/sourceofgoods/shuaxuan.png"></image>
				</view>
			</view>
			<view class="shang_xia">
				<view :class="{ selected: activeButton === '4' }" @click="handleClick('4')">
					全部
				</view>
				<view :class="{ selected: activeButton === '0' }" @click="handleClick('0')">
					带充值
				</view>
				<view :class="{ selected: activeButton === '1' }" @click="handleClick('1')">
					进行中
				</view>
				<view :class="{ selected: activeButton === '2' }" @click="handleClick('2')">
					已结束
				</view>
				<view :class="{ selected: activeButton === '3' }" @click="handleClick('3')">
					已暂停
				</view>
			</view>
		</view>
		<view class="content_xia">
			<view class="shang_sousuo">
				<uni-search-bar placeholder="货源ID查询" cancelButton="none"></uni-search-bar>
			</view>

			<!-- 如果货源数据为空，则显示提示 -->
			<view v-if="du==0" class="empty-data">
				<view class="icon">
					<image src="../../static/sourceofgoods/zanwu.png" alt="暂无数据"></image>
				</view>
				<text>暂无货源数据</text>
			</view>
			<view v-else class="huowu" v-for="opt in goodsData">
				<view class="hw_shang">
					<view class="hw_one">
						<view class="one_left">
							<view class="yuan">
								装
							</view>
							{{opt.shippingaddress}}
						</view>
						<view class="one_right" v-if="opt.status==0">
							待充值
						</view>
						<view class="one_right" v-else-if="opt.status==1">
							进行中
						</view>
						<view class="one_right" v-else-if="opt.status==2">
							已结束
						</view>
						<view class="one_right" v-else-if="opt.status==3">
							已暂停
						</view>
						<view class="one_right" v-else>
							待开始
						</view>
					</view>
					<view class="hw_two">
						<view class="yuan">
							卸
						</view>
						<view class="two_text">
							{{opt.unloadingaddress}}
						</view>
					</view>
				</view>
				<view class="hw_xia">
					<view>
						<image src="../../static/sourceofgoods/huowu.png"></image>
						<text>货物：</text>
						<text>{{opt.cargoname}}</text>
						<text class="ss">运价：</text>
						<text>{{opt.unitprice}}元/吨</text>
					</view>
					<view>
						<image src="../../static/sourceofgoods/yizhuang.png"></image>
						<text>已装：</text>
						<text>{{chushi}}/{{opt.totalweight}}吨</text>
					</view>
					<view>
						<image src="../../static/sourceofgoods/fahuoshijian.png"></image>
						<text>最晚发货：</text>
						<text>{{opt.starttime}}</text>

					</view>
					<view>
						<image src="../../static/sourceofgoods/id.png"></image>
						<text>{{opt.sourceid}}</text>

					</view>
				</view>
				<view class="anniu">
					<view class="anniu_o">
						货源统计
					</view>
					<view class="anniu_o">
						运单记录
					</view>
					<view class="anniu_p">
						再次发布
					</view>
					<view class="anniu_p">
						装车/卸车
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		reactive,
		ref
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		http
	} from '@/config/request.js'
	import "@/config/request.js";
	const goodsData = ref([]);
	const chushi = ref(0.0);
	const du = ref(0);


	const activeButton = ref(''); // 记录选中的按钮
	const cha = async (status) => {
		const res = await http({
			url: '/selectHuoYuanBYStatus/' + status,
			method: 'GET'
		})
		goodsData.value = res.shuju;
		du.value = goodsData.value.length;
		console.log(goodsData.value)
	}
	const chakan = async () => {
		const res = await http({
				url: '/selectHuoYuanq',
				method: 'GET'
			})
		console.log(res)
		goodsData.value = res.shuju;
		du.value = goodsData.value.length;
		console.log(goodsData.value)
	}

	// 点击事件
	const handleClick = (buttonName) => {
		activeButton.value = buttonName; // 更新选中的按钮
		console.log(activeButton.value)
		if (buttonName != '4') {
			cha(buttonName);
		} else {
			chakan();
		}
	};
</script>

<style lang="scss">
	.empty-data {
		width: 100%;
		height: 400rpx;
		/* 高度可以根据实际情况调整 */
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		background-color: #f8f8f8;
		border-radius: 15rpx;
		border: 1px solid #dcdcdc;
		/* 边框颜色 */
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.1);
		/* 轻微的阴影 */
		margin-top: 20rpx;
		text-align: center;
	}

	.empty-data text {
		color: #888888;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
	}

	.empty-data .icon {
		width: 100rpx;
		height: 100rpx;
		background-color: #f0f0f0;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 15rpx;
	}

	.empty-data .icon image {
		width: 100rpx;
		height: 100rpx;
	}


	.content {
		background: #0000ff;

		.content_shang {
			width: 100%;
			height: 200rpx;
			background-color: #002fa7;
			color: #fff;

			.shang_shang {
				width: 100%;
				height: 100rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;


				.shang_left {
					margin-left: 20rpx;
					font-size: 50rpx;
				}

				.shang_right {
					margin-right: 20rpx;
				}

				.shang_right image {
					width: 40rpx;
					height: 40rpx;

				}
			}

			.shang_xia {
				width: 100%;
				height: 100rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;

				view {
					font-size: 30rpx;
					width: 100rpx;
					text-align: center;
					padding-bottom: 15rpx;
					color: #d5d5d5;
				}

			}
		}

		.content_xia {
			width: 100%;
			background-color: #eeeeee;
			border-radius: 20rpx 20rpx 0 0;
			display: flex;
			flex-direction: column;
			align-items: center;
			min-height: 100vh;
			/* 让底部内容的高度至少是屏幕的高度 */
			padding-bottom: 20rpx;
			/* 适当添加一些底部空间 */


			.shang_sousuo {
				width: 100%;
				height: 100rpx;

				uni-search-bar {
					width: 100%;
					height: 100rpx;
					background-color: #ffffff;
					border-radius: 50rpx;
					margin: 0 auto;
					padding: 0;

				}
			}

			.huowu {
				width: 90%;
				height: 420rpx;
				display: flex;
				background-color: #fff;
				border-radius: 20rpx;
				margin-top: 20rpx;
				flex-wrap: wrap;
				margin-bottom: 20rpx;
				justify-content: space-around;


				.hw_shang {

					width: 100%;
					height: 100rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					margin: 30rpx;
					font-size: 27rpx;

					.hw_one {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin: 10rpx;


						.one_left {
							display: flex;
							align-items: center;

							.yuan {
								width: 40rpx;
								height: 40rpx;
								background-color: #002fa7;
								border-radius: 50%;
								text-align: center;
								line-height: 40rpx;
								margin-right: 20rpx;
								font-size: 20rpx;
								color: #fff;
							}
						}

						.one_right {
							color: #ff3939;
							font-weight: bold;
						}
					}

					.hw_two {
						display: flex;
						margin: 10rpx;
						align-items: center;

						.yuan {
							width: 40rpx;
							height: 40rpx;
							background-color: #ff3939;
							border-radius: 50%;
							text-align: center;
							line-height: 40rpx;
							margin-right: 20rpx;
							font-size: 20rpx;
							color: #fff;
						}
					}

				}

				.hw_xia {
					width: 100%;
					height: 210rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					margin-left: 40rpx;

					margin-top: -40rpx;
					font-size: 25rpx;

					.ss {
						margin-left: 100rpx;
					}
				}

				.anniu {
					display: flex;
					height: 50rpx;
					justify-content: space-around;
					padding-left: 50rpx;
					padding-bottom: 10rpx;

					.anniu_o {
						width: 110rpx;
						height: 50rpx;
						background-color: #fff;
						border-radius: 10rpx;
						text-align: center;
						line-height: 50rpx;
						color: #909090;
						font-size: 25rpx;
						border: 1px solid #ababab;
					}

					.anniu_p {
						width: 110rpx;
						height: 50rpx;
						background-color: #edfcff;
						text-align: center;
						line-height: 50rpx;
						border-radius: 10rpx;
						color: #5555ff;
						font-size: 25rpx;
						border: 1px solid #ababab;
					}

				}
			}


		}
	}

	.anniu view {
		margin-right: 15rpx;
	}

	.hw_xia image {
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
		margin-left: 20rpx;
	}

	.hw_xia view {
		display: flex;
		align-items: center;
		margin-top: 20rpx;

	}

	.shang_xia view.selected {
		color: #002fa7;
		/* 选中后的字体颜色 */
		border-bottom: 4rpx solid #fff;
		/* 选中时的下边框 */
	}
</style>